<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<title>SIMRI - Consulta Aquisição</title>
</h:head>
<h:body>
	<center>
		<f:view>
			<p:menubar>
				<p:submenu label="Sensor">
					<p:menuitem value="Consultar por Sensor" url="ConsultaSensor.xhtml" />
					<p:menuitem value="Consultar Aquisições"
						url="ConsultaAquisicao.xhtml" />
					<p:menuitem value="Listar todos os sensores"
						url="ListarSensores.xhtml" />
				</p:submenu>
			</p:menubar>
			<h3>Consulta de Aquisições dos Sensores</h3>
			<h:form id="fConsultaAquisicao">
				<table>
					<tr>
						<td>Pesquisar por:</td>
						<td><p:selectOneMenu id="selPesquisa"
								value="#{consultaAqBean.pesquisaSel}">
								<f:selectItem itemLabel="ID Sensor" itemValue="0" />
								<f:selectItem itemLabel="Mensagem" itemValue="1" />
								<f:selectItem itemLabel="Data" itemValue="2" />
								<p:ajax event="change" listener="#{consultaAqBean.selChange}"
									update="entPesquisa,dataPesquisa" />
							</p:selectOneMenu></td>
						<td><p:selectBooleanCheckbox id="selGrafico"
								value="#{consultaAqBean.mostrarGrafico}"
								itemLabel="Mostrar Gráfico">
								<p:ajax event="change" listener="#{consultaAqBean.grafChange}"
									update="grafAquisicoes" />
							</p:selectBooleanCheckbox></td>
					</tr>
					<tr>
						<td>Pesquisa:</td>
						<td><p:inputText id="entPesquisa"
								value="#{consultaAqBean.entradaPesquisa}"
								onclick="clickclear(this,'Digite aqui o valor a ser pesquisado')"
								onblur="clickrecall(this,'Digite aqui o valor a ser pesquisado')"
								size="32" disabled="#{consultaAqBean.desativarEntrada}"
								widgetVar="wEntPesquisa" /></td>
						<td><p:calendar id="dataPesquisa"
								value="#{consultaAqBean.dataPesquisa}" locale="pt_BR"
								pattern="dd/MM/yyyy HH:mm:ss"
								disabled="#{consultaAqBean.desativarData}"
								widgetVar="wDtPesquisa" /></td>
					</tr>
					<tr>
						<td colspan="2" align="center"><p:commandButton
								value="Pesquisar" action="#{consultaAqBean.pesquisar}"
								ajax="false" /></td>
					</tr>
				</table>
				<p:dialog header="Resultado da Busca:" widgetVar="dlgResult"
					rendered="#{consultaAqBean.mostrarMensagem}" visible="true">
					<h:panelGrid id="gridMsg" columns="1">
						<h:outputText id="msg" value="#{consultaAqBean.mensagem}" />
					</h:panelGrid>
				</p:dialog>
				<p:dataTable id="tabAquisicoes" var="aq"
					value="#{consultaAqBean.aquisicoes}" paginator="true" rows="10"
					emptyMessage="Sem dados encontrados!">
					<f:facet name="header">
						<h2>Lista de Aquisições Encontradas:</h2>
					</f:facet>
					<p:columns value="#{consultaAqBean.colunas}" var="coluna"
						columnIndexVar="j">
						<f:facet name="header">#{coluna}</f:facet>
						<h:outputText value="#{aq[j]}" />
					</p:columns>
					<f:facet name="footer">
						Aquisições encontradas: #{fn:length(consultaAqBean.aquisicoes)}
					</f:facet>
				</p:dataTable>
				<p:lineChart id="grafAquisicoes"
					value="#{consultaAqBean.graficoModel}" legendPosition="ne"
					rendered="#{consultaAqBean.mostrarGrafico}" />
			</h:form>
		</f:view>
	</center>
	<script type="text/javascript" src="js/locales.js" />
	<script type="text/javascript">
		function clickclear(thisfield, defaulttext) {
			if (thisfield.value == defaulttext) {
				thisfield.value = "";
			}
		}
		function clickrecall(thisfield, defaulttext) {
			if (thisfield.value == "") {
				thisfield.value = defaulttext;
			}
		}
	</script>
</h:body>
</html>